<?php

if (!defined('BASEPATH'))
     exit('No direct script access allowed');

/*
 * Detect invalid result froms restful services
 */

class rest_utility {

     private $result;

     public function __construct() {

          $this->CI = &get_instance();
     }

     public function verify($result) {

          $this->result = $result;

          // precheck
          if (gettype($this->result) == 'string'): // error message from rest server
               return FALSE;
          endif;
          if (gettype($this->result) == 'array' && count($this->result) > 0): // result is asociative array with > 1 elements
               return TRUE;
          endif;

          $valid = TRUE;

          // check for result count
          if (!count($this->result) > 0):
               return FALSE;
          endif;

          if(! $this->_check_unknown_method()):
               return FALSE;
          endif;

          return $valid;
     }

     private function _check_unknown_method() {


          if (isset($this->result->status) && isset($this->result->error)):
               return FALSE;
          endif;

          return TRUE;
     }

}

?>
